home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / microcrn / issue_49.arc / DRV_INFO.ARC / DRV_INFO.PAS
Pascal/Delphi Source File  |  1989-07-11  |  8KB  |  169 lines

  1. (* Micro Cornucopia Magazine - Issue #49
  2.    Tech Tips Figure 1 - Find Number of Drives in System *)
  3.  
  4. (* PROGRAM DRV_INFO.PAS     AUTHOR - JEFFREY SCOTT DONOVAN          *)
  5. (*------------------------------------------------------------------*)
  6.  
  7. program drv_info;
  8. uses crt,dos;                            (* TURBO CRT AND DOS UNITS *)
  9.  
  10. type
  11.   drive_ids=record                    (* DISK-SUBSYSTEM INFORMATION *)
  12.       no_drive:integer;                   (* NUMBER OF TOTAL DRIVES *)
  13.       no_logical:integer;               (* NUMBER OF LOGICAL DRIVES *)
  14.       no_floppy:integer;                 (* NUMBER OF FLOPPY DRIVES *)
  15.       no_hard:integer;                     (* NUMBER OF HARD DRIVES *)
  16.       drive_chars:array[1..10] of char;   (* DRIVE CHARACTERS ARRAY *)
  17.       drive_type:array[1..10] of integer;   (* ARRAY OF DRIVE TYPES *)
  18.       drive_numb:array[1..10] of integer; (* DOS DRIVE NUMBER ARRAY *)
  19.       c_drive:integer;                             (* CURRENT DRIVE *)
  20.       c_drive_ch:char;                   (* CURRENT DRIVE CHARACTER *)
  21.       last_drive:char;                      (* LAST DRIVE CHARACTER *)
  22.       end;
  23.  
  24. var
  25.   drives:drive_ids;                     (* GLOBAL INFO ABOUT DRIVES *)
  26.   regs:registers;                                  (* DOS REGISTERS *)
  27.  
  28. (* MODULE : GET CURRENT DRIVE                                       *)
  29. (*------------------------------------------------------------------*)
  30. (* Returns current drive number.   A=1, B=2, C=3, ETC.              *)
  31. (*                                                                  *)
  32. function get_current_drive:integer;
  33.    begin
  34.    regs.ah:=$19;                   (* FUNCTION 19H, GET CURRENT DRV *)
  35.    intr($21,regs);                                       (* INT 21H *)
  36.    get_current_drive:=regs.al;               (* RETURN DRIVE NUMBER *)
  37.    end;
  38. (*------------------------------------------------------------------*)
  39.  
  40. (* MODULE : GET NUMBER LOGICAL DRIVES                               *)
  41. (*------------------------------------------------------------------*)
  42. (* Return number of logical drives in system.                       *)
  43. (* NOTE : DOS 3.O + returns either 5 or the last drive in system.   *)
  44. (*                                                                  *)
  45. function get_number_logical_drives:integer;
  46.    var
  47.       current:integer;
  48.    begin
  49.    current:=get_current_drive;       (* GET CURRENT DRIVE TO SET TO *)
  50.    regs.ah:=$0E;                         (* FUNCTION 0EH, SET DRIVE *)
  51.    regs.dl:=current;                        (* SET TO CURRENT DRIVE *)
  52.    intr($21,regs);                                       (* INT 21H *)
  53.    get_number_logical_drives:=regs.al;   (* RETURN # LOGICAL DRIVES *)
  54.    end;
  55. (*------------------------------------------------------------------*)
  56.  
  57. (* MODULE : GET NUMBER FLOPPY DRIVES                                *)
  58. (*------------------------------------------------------------------*)
  59. (* Return the number of floppy drives.                              *)
  60. (*                                                                  *)
  61. function get_number_floppy_drives:integer;
  62.    var
  63.       drives_there,number:integer;
  64.    begin
  65.    number:=-1;                                  (* SET NUMBER TO -1 *)
  66.    intr($11,regs);                        (* INT 11, EQUIPMENT INFO *)
  67.    drives_there:=regs.ax and 1;       (* FLOPPY INSTALLED, BIT0 = 1 *)
  68.    if drives_there=1 then          (* IF FLOPPYS INSTLLD, HOW MANY? *)
  69.       number:=(regs.ax shr 6) and 4;    (* BIT 6-7 HOLD APPROP INFO *)
  70.    get_number_floppy_drives:=number+1;      (* RETURN # OF FLOPPIES *)
  71.    end;
  72. (*------------------------------------------------------------------*)
  73.  
  74. (* MODULE : GET DRIVE DATA                                          *)
  75. (*------------------------------------------------------------------*)
  76. (* Get all the drive data ness. Store in global var drives.         *)
  77. (*                                                                  *)
  78. procedure get_drive_data;
  79.    var
  80.       loop,count,h_count,start:integer;
  81.    begin
  82.    count:=0;                            (* SET TOTAL COUNTS TO ZERO *)
  83.    h_count:=0;
  84.  
  85.    for loop:=1 to drives.no_floppy do  (* ASSIGN FLOPPY INFO IF ANY *)
  86.       begin                          (* SET CORRECT DRIVE CHARACTER *)
  87.       drives.drive_chars[loop]:=chr(loop+64);
  88.       drives.drive_type[loop]:=1;       (* SET DRIVE TYPE TO FLOPPY *)
  89.       drives.drive_numb[loop]:=loop-1;      (* LOGICAL DRIVE NUMBER *)
  90.       inc(count);                          (* INC TOTAL DRIVE COUNT *)
  91.       end;
  92.                                           (* NO MORE THAN 10 DRIVES *)
  93.    if (drives.no_logical>10) then drives.no_logical:=10;
  94.  
  95.    start:=drives.no_floppy+1;        (* FIGURE START NUMBER H-DRIVE *)
  96.    if (drives.no_floppy<=1) then inc(start);
  97.    if (drives.no_floppy=0) then inc(start);
  98.  
  99.    for loop:=start to drives.no_logical do     (* CHECK EACH HDRIVE *)
  100.       begin
  101.       regs.ah:=$1C;                                 (* FUNCTION 1CH *)
  102.       regs.dl:=loop;                    (* SET DRIVE NUMBER TO LOOP *)
  103.       intr($21,regs);                                    (* INT 21H *)
  104.  
  105.       if (regs.al<>$FF) then        (* IF DRIVE IS VALID, SET APPR. *)
  106.          begin                       (* SET CORRECT DRIVE CHARACTER *)
  107.                                        (* SET DRIVE TYPE TO H-DRIVE *)
  108.                                    (* FIGURE ACTUAL LOGICAL DRIVE # *)
  109.          drives.drive_chars[loop-start+drives.no_floppy+1]:=
  110.                  chr(loop+64);
  111.          drives.drive_type[loop-start+drives.no_floppy+1]:=2;
  112.          drives.drive_numb[loop-start+drives.no_floppy+1]:=loop-1;
  113.  
  114.          inc(count);                       (* INC TOTAL DRIVE COUNT *)
  115.          inc(h_count);                         (* INC H-DRIVE COUNT *)
  116.          end;
  117.  
  118.       end;
  119.    drives.no_hard:=h_count;            (* ASSIGN NUMBER HARD DRIVES *)
  120.                                    (* ASSIGN NUMBER OF TOTAL DRIVES *)
  121.    drives.no_drive:=h_count+drives.no_floppy;
  122.    end;
  123. (*------------------------------------------------------------------*)
  124.  
  125. (* MODULE : WRITE DISK CHOICES                                      *)
  126. (*------------------------------------------------------------------*)
  127. (* Write all available drives (up to 10), and write the drive type. *)
  128. (*                                                                  *)
  129. procedure write_disk_choices;
  130.    var loop:integer;
  131.    begin
  132.    for loop:=1 to drives.no_drive do     (* LOOP FROM FIRST TO LAST *)
  133.       begin
  134.       write(drives.drive_chars[loop],': ');(* WRITE DRIVE CHARACTER *)
  135.                                                 (* WRITE DRIVE TYPE *)
  136.       if (drives.drive_type[loop]=1) then write('[ Floppy  ]')
  137.       else write('[ H-Drive ]');
  138.                                       (* WRITE LOGICAL DRIVE NUMBER *)
  139.       writeln('  ,DOS Logical Disk # ',drives.drive_numb[loop]:2);
  140.       end;
  141.    end;
  142. (*------------------------------------------------------------------*)
  143.  
  144. begin
  145. clrscr;
  146.                                           (* GET ALL THE DRIVE INFO *)
  147.  
  148. drives.no_floppy:=get_number_floppy_drives;
  149. drives.no_logical:=get_number_logical_drives;
  150. drives.c_drive:=get_current_drive;
  151. get_drive_data;
  152. drives.c_drive_ch:=chr(drives.c_drive+65);
  153. drives.last_drive:=chr(drives.no_logical-drives.no_floppy+65);
  154.  
  155.                                          (* WRITE ALL THE DISK INFO *)
  156. writeln('SYSTEM DISK INFORMATION');
  157. writeln('-----------------------');
  158. writeln('Number   Logical Drives = ',drives.no_logical:1);
  159. writeln('Number   Floppy  Drives = ',drives.no_floppy:1);
  160. writeln('Number   Hard    Drives = ',drives.no_hard:1);
  161. writeln('Current Drive           = ',drives.c_drive_ch);
  162. writeln('Last Drive              = ',drives.last_drive);
  163. writeln;
  164. writeln('ACTUAL DRIVES IN SYSTEM');
  165. writeln('-----------------------');
  166.  
  167. write_disk_choices;
  168. end.
  169.